/* NovoDev_CH341.cpp */


#include "pch.h"
#include "NovoDev_CH341.h"

#pragma comment(lib, "libs/CH341DLL.LIB")

#define WRITE_WORD   0 
#define DUMMY_WORD   0xFFFFFFFF
#define READ_WORD    1
#define BURST_WRITE_LENGTH   1024*10
#define BURST_READ_LENGTH    1024*4


int NovoDev_CH341::Novo_InitDev(void* config)
{
	return 0;
}

int NovoDev_CH341::Novo_EnumDevice()
{
	int ret = 0;
	return ret;
}

int NovoDev_CH341::Novo_SetDeviceId(int DevID)
{
	int ret = 0;
	mDevID = DevID;
	return ret;
}

int NovoDev_CH341::Novo_GetFwVersion(char*& FwVersion, int iChip)
{
	int ret = ERR_NOT_SUPPORT;
	return ret;
}

int NovoDev_CH341::Novo_GetHardwareVersion(char*& HwVersion)
{
	int ret = ERR_NOT_SUPPORT;
	return ret;
}

void NovoDev_CH341::Novo_GetName(char* pDevName)
{
	pDevName = (char*)DEV_NAME;
	return;
}

int NovoDev_CH341::Novo_ResetSensor(int time)
{
	return ERR_NOT_SUPPORT;
}

int NovoDev_CH341::Novo_OpenDevice()
{
	int ret = 0;
	hDev = CH341OpenDevice(mDevID);
	if (hDev != NULL)
		ret = 0;
	else
		ret = -1;

	return ret;
}

int NovoDev_CH341::Novo_CloseDevice()
{
	int ret = 0;
	CH341CloseDevice(mDevID);
	return ret;
}

int NovoDev_CH341::Novo_IIC_SetIndex(int IICIndex)
{
	int ret = ERR_NOT_SUPPORT;

	return ret;
}

int NovoDev_CH341::Novo_IIC_Init(void* config)
{
	int ret = 0;
	ULONG iMode = (ULONG)config;
	ret = CH341SetStream(mDevID, ULONG(iMode)) ? SUCCESS : ERR_Failed;

	return ret;
}

int NovoDev_CH341::Novo_IIC_GetSlaveAddr(short* pSlaveAddr)
{
	int ret = ERR_IIC_NO_DEV;
	//UCHAR rdData = 0;
	//for (short ix = 1; ix <= 254; ix++)
	//{
	//	if ((ret = NOVO_IIC_Rd_Single_U8(ix, 0, &rdData)) != 0)
	//	{
	//		*pSlaveAddr = ix;
	//		break;
	//	}
	//}

	return ret;
}